package com.big.tree.controller;

import com.big.tree.service.observer.UserArrearsPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author big tree
 *   当创建用户欠费事件时，监听这个事件的邮件欠费和短信欠费将会触发
 *
 */
@RestController
@RequestMapping("/design")
public class ObserverController {

    @Autowired
    private UserArrearsPublisher userArrearsPublisher;

    /**
     * 观察者模式
     */
    @GetMapping("/observer")
    public void springEvent(){
        userArrearsPublisher.arrears("zhangsan");
        /** 控制台打印
         c.b.t.s.observer.UserArrearsPublisher    : 被观察者 用户欠费,用户名称
         c.b.tree.service.observer.EmailService   : 邮箱欠费通知，你好 zhangsan ,请尽快缴费啊啊啊啊！
         c.big.tree.service.observer.SmsService   : 短信欠费通知，你好 zhangsan ,请尽快缴费啊啊啊啊！
        */
    }

}
